/*
	DSA Project on use of arrays and linked lists to obtain the same functionality as the functions of list data structure in Python
*/

#include<stdio.h>
#include<malloc.h>

struct node{
       int val;
       struct node *next;
       };

struct node *front=NULL;
struct node *rear=NULL;

void display(struct node *ptr,struct node *front)
{
struct node *p=front;
while(p!=NULL)
	{
	printf("%d ",p->val);
	p=p->next;
	}
}


/*
	1) <list>.append()
*/

void append(struct node *ptr, struct node *t)
{
       struct node *new;
       int number;
       ptr=t;
       struct node* front = ptr;
       new=malloc(sizeof(struct node));
       printf("Value of new node:");
       scanf("%d",&number);
       new->val=number;
       new->next=NULL;
       while(ptr->next!=NULL)
       {
               ptr=ptr->next;
       }
       ptr->next=new;
       display(front,t);
}


/*
	<list>.count()
	counting the number of occurence of the given element
*/
void count(struct node *ptr) 
{ 
	int count=0;
	int number;
 	printf("Enter the number whose count is desired:\n");
 	scanf("%d",&number);
 	while(ptr!=NULL)
 	{
		if(number==ptr->val) 
 	 	{
			count++;
		}
 	ptr=ptr->next; 
}
 	printf("Count of %d is: %d\n",number,count);
}


	
//References: http://www.dreamincode.net/code/snippet82.htm
